package com.library.mapper;

import com.github.pagehelper.Page;
import com.library.dto.PageQueryDTO;
import com.library.entity.BorrowHistory;
import com.library.entity.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface BorrowHistoryMapper {


    /**
     * 新增借阅记录
     * @param borrowHistory
     */
    @Insert("insert into borrow_history" +
            "(user_id, book_id, book_title, borrow_time, return_time, status, return_deadline) " +
            "values" +
            "(#{userId}, #{bookId}, #{bookTitle}, #{borrowTime}, #{returnTime}, #{status}, #{returnDeadline})"
            )
    void insert(BorrowHistory borrowHistory);

    /**
     * 更新借阅记录
     * @param borrowHistory
     */
    Integer update(BorrowHistory borrowHistory);

    /**
     * 分页查询
     * @param pageQueryDTO
     * @return
     */
    Page<BorrowHistory> pageQuery(PageQueryDTO pageQueryDTO, Long userId);

    @Select("select count(*) from borrow_history where user_id = #{userId} and book_id = #{bookId} and status = 0")
    int countByUserIdAndBookId(Long userId, Long bookId);
}
